# lathe_to_cutting_frame.py

from __future__ import division

from ot_simulator import setup
from ot_simulator.component import component

class lathe_to_cutting_frame(component.component):
    r'''This converts a lathe into a cutting frame.

    ===============  ==========================
     Input setting   
    ===============  ==========================
    <none>
    ===============  ==========================

    ======================  ======================================
    Output setting
    ======================  ======================================
    work_transform          intermediate: for just the work stack
    tool_transform          intermediate: for just the tool stack
    work_to_tool_transform  the final cutting_frame transform
    ======================  ======================================
    '''
    input_parameters = ('sr',)

    def __init__(self, work_stack, tool_stack, **kws):
        component.component.__init__(self, **kws)
        self.work_stack = tuple(work_stack)
        self.tool_stack = tuple(tool_stack)

    def register(self, params):
        super(lathe_to_cutting_frame, self).register(params)
        setup.register_stack(self.tool_stack, params)
        setup.register_stack(self.work_stack, params)

    def work_transform(self, params):
        r'''Calculate the work_transform
        '''
        work_transform = setup.simulate_stack(self.work_stack, params)
        self.set_param(params, 'work_transform', work_transform)
        return work_transform

    def tool_transform(self, params):
        r'''Calculate the tool_transform
        '''
        tool_transform = setup.simulate_stack(self.tool_stack, params)
        self.set_param(params, 'tool_transform', tool_transform)
        return tool_transform

    def work_to_tool_transform(self, params):
        r'''Calculate the work_to_tool_transform.
        '''
        tool_transform = self.get_param(params, 'tool_transform')
        work_transform = self.get_param(params, 'work_transform')
        work_to_tool_transform = tool_transform.subtract(work_transform)
        self.set_param(params, 'work_to_tool_transform', work_to_tool_transform)
        return work_to_tool_transform

    def get_transform(self, params, transform_in):
        work_to_tool_transform = \
          self.get_param(params, 'work_to_tool_transform')
        return transform_in.add(work_to_tool_transform)

